﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 版权所有 (c) 2023  NJRN 保留所有权利。
 * CLR版本：4.0.30319.42000
 * 机器名称：DUXUELI
 * 公司名称：
 * 命名空间：BusinessRule.JG
 * 唯一标识：939ed8c1-b1db-4ce5-a79a-d1fc331f339c
 * 文件名：Check
 * 当前用户域：DUXUELI
 * 
 * 创建者：DELL
 * 电子邮箱：（你的电子邮箱地址）
 * 创建时间：2023-07-19 09:11:29
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>

using BusinessEntity.Assets;
using BusinessRepository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace BusinessRule
{
    /// <summary>
    /// Check 的摘要说明
    /// </summary>
    public class Check
    {
        public static async Task<DataTable> GetCols(string lx)
        {
            string sql = "select LOWER(col) as col,xm as name,xh from TB_TableSet where lx='"+lx+"' and isshow='1' order by xh";
            return await new RepositoryFactory().BaseRepository().FindTable(sql);
        }

        #region "收支明细表"
        public static async Task InsertSZMXBDZ(SZMXBDZ b)
        {
            string sql = "delete from SZMXBDZ where areacode='"+b.areacode+"' and issue='"+b.issue+"'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            await new RepositoryFactory().BaseRepository().Insert(b);
        }

        public static async Task<DataTable> GetSzmxb(string areacode, string kjqj,string org,string datatype)
        {
            if (org.Contains("("))
            {
                if (datatype == "1")
                {
                    string sql = "select * from SZMXBDZ where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from SZMXB where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
            else
            {
                if (datatype == "1")
                {
                    string sql = "select * from SZMXBDZ where areacode like '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from SZMXB where areacode like '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
        }
        #endregion

        #region "债务债权表"
        public static async Task InsertZWZQBDZ(ZWZQBDZ b)
        {
            string sql = "delete from ZWZQBDZ where areacode='" + b.areacode + "' and issue='" + b.issue + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            await new RepositoryFactory().BaseRepository().Insert(b);
        }

        public static async Task<DataTable> GetZWZQB(string areacode, string kjqj, string org,string datatype)
        {
            if (org.Contains("("))
            {
                if (datatype == "1")
                {
                    string sql = "select * from ZWZQBDZ where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from ZWZQB where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
            else
            {
                if (datatype == "1")
                {
                    string sql = "select * from ZWZQBDZ where areacode like '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from ZWZQB where areacode like '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
        }
        #endregion

        #region "科目余额表"
        public static async Task InsertKMYEBDZ(KMYEBDZ b)
        {
            string sql = "delete from KMYEBDZ where areacode='" + b.areacode + "' and issue='" + b.issue + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            await new RepositoryFactory().BaseRepository().Insert(b);
        }

        public static async Task<DataTable> GetKMYEB(string areacode, string kjqj, string org,string datatype)
        {
            if (org.Contains("("))
            {
                if (datatype == "1")
                {
                    string sql = "select * from KMYEBDZ where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from KMYEB where areacode int " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
            else
            {
                if (datatype == "1")
                {
                    string sql = "select * from KMYEBDZ where areacode like '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from KMYEB where areacode like  '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
        }
        #endregion

        #region "资产负债表"
        public static async Task InsertZCFZBDZ(ZCFZBDZ b)
        {
            string sql = "delete from ZCFZBDZ where areacode='" + b.areacode + "' and issue='" + b.issue + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            await new RepositoryFactory().BaseRepository().Insert(b);
        }

        public static async Task<DataTable> GetZCFZB(string areacode, string kjqj, string org,string datatype)
        {
            if (org.Contains("("))
            {
                if (datatype == "1")
                {
                    string sql = "select * from ZCFZBDZ where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from ZCFZB where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
            else
            {
                if (datatype == "1")
                {
                    string sql = "select * from ZCFZBDZ where areacode like '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from ZCFZB where areacode like  '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }

        }
        #endregion

        #region "收益分配表"
        public static async Task InsertSYFPBDZ(SYFPBDZ b)
        {
            string sql = "delete from SYFPBDZ where areacode='" + b.areacode + "' and issue='" + b.issue + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            await new RepositoryFactory().BaseRepository().Insert(b);
        }

        public static async Task<DataTable> GetSYFPB(string areacode, string kjqj, string org,string datatype)
        {
            if (org.Contains("("))
            {
                if (datatype == "1")
                {
                    string sql = "select * from SYFPBDZ where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from SYFPB where areacode in " + org + " and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
            else
            {
                if (datatype == "1")
                {
                    string sql = "select * from SYFPBDZ where areacode like '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
                else
                {
                    string sql = "select * from SYFPB where areacode like '" + org + "%' and issue='" + kjqj + "'";
                    if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                    {
                        sql += " and areacode like '" + areacode + "%'";
                    }
                    sql += " order by areacode";
                    return await new RepositoryFactory().BaseRepository().FindTable(sql);
                }
            }
        }
        #endregion


        #region "资产负债表财务"
        public static async Task InsertZCFZBCWDZ(ZCFZBCWDZ b)
        {
            string sql = "delete from ZCFZBCWDZ where org='" + b.org + "' and kjqj='" + b.kjqj + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            await new RepositoryFactory().BaseRepository().Insert(b);
        }

        public static async Task<DataTable> GetZCFZBCW(string areacode, string kjqj,string datatype)
        {

            if (datatype == "1")
            {
                string sql = "select * from ZCFZBCWDZ where kjqj='" + kjqj + "'";
                if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                {
                    sql += " and org='" + areacode + "'";
                }
                sql += " order by xh";
                return await new RepositoryFactory().BaseRepository().FindTable(sql);
            }
            else
            {
                string sql = "select * from ZCFZBCW where kjqj='" + kjqj + "'";
                if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                {
                    sql += " and org='" + areacode + "'";
                }
                sql += " order by xh";
                return await new RepositoryFactory().BaseRepository().FindTable(sql);
            }
        }
        #endregion

        #region "利润表财务"
        public static async Task InsertLRBCWDZ(LRBCWDZ b)
        {
            string sql = "delete from LRBCWDZ where org='" + b.org + "' and kjqj='" + b.kjqj + "'";
            await new RepositoryFactory().BaseRepository().ExecuteSql(sql);
            await new RepositoryFactory().BaseRepository().Insert(b);
        }

        public static async Task<DataTable> GetLRBCW(string areacode, string kjqj,string datatype)
        {
            if (datatype == "1")
            {
                string sql = "select * from LRBCWDZ where kjqj='" + kjqj + "'";
                if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                {
                    sql += " and org='" + areacode + "'";
                }
                sql += " order by xh";
                return await new RepositoryFactory().BaseRepository().FindTable(sql);
            }
            else
            {
                string sql = "select * from LRBCW where kjqj='" + kjqj + "'";
                if (!string.IsNullOrEmpty(areacode) && areacode != "null" && areacode != "undefined")
                {
                    sql += " and org='" + areacode + "'";
                }
                sql += " order by xh";
                return await new RepositoryFactory().BaseRepository().FindTable(sql);
            }
        }
        #endregion
    }
}
